<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>WebSocket 控制台打印</title>
</head>
<body>
<script>
    // 建立 WebSocket 连接
    const ws = new WebSocket("ws://localhost:8004/websocket/alert");

    // 连接成功时打印
    ws.onopen = () => {
        console.log("WebSocket 连接已建立");
    };

    // 收到消息时打印
    ws.onmessage = (event) => {
        console.log("📨客户端收到消息:", event.data);
    };

    // 连接关闭时打印
    ws.onclose = () => {
        console.log("WebSocket 连接已关闭");
    };

    // 发生错误时打印
    ws.onerror = (error) => {
        console.error("WebSocket 错误:", error);
    };
</script>
</body>
</html>